package cn.lyn4ever.goods.web.controller;

import cn.lyn4ever.common.R;
import cn.lyn4ever.goods.web.service.GoodsSpuService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Api( description = "商品SPU接口")
@RestController
@RequestMapping("goodsSpu")
public class GoodsSpuController {
    /**
     * 服务对象
     */
    @Resource
    private GoodsSpuService goodsSpuService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "查询商品详情", notes = "通过商品ID查询商品详情")
    @GetMapping("getGoodsDetail/{id}")
    @ApiImplicitParam(name = "id", value = "商品ID", required = true, dataType = "string", paramType = "query", defaultValue = "1")
    public R selectOne(@PathVariable("id") Integer id) {
       return R.ok("获取成功").put("data",this.goodsSpuService.queryById(id));


    }

    /**
     * 查询全部商品
     *
     * @return
     */
    @ApiOperation(value = "查询全部商品", notes = "查询全部商品用于商品列表显示")
    @GetMapping("getAllGoods")
    public R getAllGoods(){
        return R.ok("获取成功").put("data",this.goodsSpuService.getAllGoodsSpu());
    }

    /**
     * 获取商品总数
     *
     * @return
     */
    @GetMapping("getGoodsCount")
    public R getGoodsCount(){
        return R.ok("获取成功").put("data",this.goodsSpuService.getGoodsCount());
    }

}